<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="客户编号" prop="companyCode">
        <el-input
          v-model="queryParams.companyCode"
          placeholder="请输入客户编号"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户简称" prop="companyName">
        <el-input
          v-model="queryParams.companyName"
          placeholder="请输入客户简称"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户全称" prop="fullName">
        <el-input
          v-model="queryParams.fullName"
          placeholder="请输入客户全称"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>

      <el-form-item label="客户状态" prop="companyStatus">
        <el-select
          v-model="queryParams.companyStatus"
          placeholder="客户状态"
          clearable
          style="width: 200px"
        >
          <el-option
            v-for="dict in company_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="付款方式" prop="paymentType">
        <el-select
          v-model="queryParams.paymentType"
          placeholder="请选择"
          clearable
          style="width: 200px"
        >
          <el-option
            v-for="dict in pay_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="审核状态" prop="approveStatus">
        <el-select
          v-model="queryParams.approveStatus"
          placeholder="请选择"
          clearable
          style="width: 200px"
        >
          <el-option
            v-for="dict in company_audit_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="结算类型" prop="settlementVersionType">
        <el-select
          v-model="queryParams.settlementVersionType"
          placeholder="请选择"
          clearable
          style="width: 200px"
        >
          <el-option
            v-for="dict in company_settlement_version_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['yanjing:company:add']"
          >添加客户</el-button
        >
      </el-col>
      <!--      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="Edit"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['system:post:edit']"
        >修改</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="multiple"
          @click="handleBatchAudit"
          v-hasPermi="['yanjing:company:batchAudit']"
          >提交审核</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="multiple"
          @click="handleAuditTrue"
          v-hasPermi="['yanjing:company:batchAuditTrue']"
          >审核通过</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Edit"
          :disabled="multiple"
          @click="handleAuditFalse"
          v-hasPermi="['yanjing:company:batchAuditFalse']"
          >审核不通过</el-button
        >
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Edit"
          :disabled="multiple"
          @click="handleBackUpdate"
          v-hasPermi="['yanjing:company:edit']"
          >下架修改</el-button
        >
      </el-col>

      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="companyList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="客户编号"
        align="center"
        prop="companyCode"
        width="110"
      />
      <el-table-column
        label="客户全称"
        align="center"
        prop="fullName"
        min-width="150"
      />
      <el-table-column label="客户简称" align="center" prop="companyName" />
      <el-table-column
        label="付款方式"
        align="center"
        prop="paymentType"
        width="110"
      >
        <template #default="scope">
          <dict-tag :options="pay_type" :value="scope.row.paymentType" />
        </template>
      </el-table-column>
      <el-table-column
        label="付款比例"
        align="center"
        prop="paymentRatio"
        width="80"
      >
        <template #default="scope">
          <span>{{ scope.row.paymentRatio }}%</span>
        </template>
      </el-table-column>
      <el-table-column
        label="结算类型"
        align="center"
        prop="settlementVersionType"
        width="80"
      >
        <template #default="scope">
          <dict-tag
            :options="company_settlement_version_type"
            :value="scope.row.settlementVersionType"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="客户状态"
        align="center"
        prop="companyStatus"
        width="80"
      >
        <template #default="scope">
          <dict-tag
            :options="company_status"
            :value="scope.row.companyStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="审核状态"
        align="center"
        prop="approveStatus"
        width="80"
      >
        <template #default="scope">
          <dict-tag
            :options="company_audit_status"
            :value="scope.row.approveStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="联系人姓名"
        align="center"
        prop="linkName"
        width="110"
      />
      <el-table-column
        label="联系电话"
        align="center"
        prop="linkMobile"
        width="110"
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="160"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        min-width="150"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            link
            type="primary"
            icon="View"
            @click="handleView(scope.row, scope.index)"
            >详细</el-button
          >
          <el-button
            link
            type="primary"
            v-if="
              scope.row.approveStatus === 'CREATE' ||
              scope.row.approveStatus === 'FAIL'
            "
            icon="Edit"
            @click="handleBatchUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            link
            type="primary"
            icon="Edit"
            @click="handleUpdate(scope.row)"
            >修改结算类型</el-button
          >
          <el-button
            v-if="scope.row.companyStatus === 'NORMAL'"
            link
            type="primary"
            icon="Edit"
            @click="handleDisable(scope.row)"
            >停用</el-button
          >
          <el-button
            v-if="scope.row.companyStatus === 'CANCEL'"
            link
            type="primary"
            icon="Edit"
            @click="handleEnable(scope.row)"
            >启用</el-button
          >

          <el-button
            link
            type="primary"
            v-if="
              scope.row.approveStatus === 'CREATE' ||
              scope.row.approveStatus === 'FAIL'
            "
            icon="Delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改岗位对话框 -->
    <!--    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="companyRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="岗位名称" prop="postName">
          <el-input v-model="form.postName" placeholder="请输入岗位名称" />
        </el-form-item>
        <el-form-item label="岗位编码" prop="postCode">
          <el-input v-model="form.postCode" placeholder="请输入编码名称" />
        </el-form-item>
        <el-form-item label="岗位顺序" prop="postSort">
          <el-input-number v-model="form.postSort" controls-position="right" :min="0" />
        </el-form-item>
        <el-form-item label="岗位状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
                v-for="dict in sys_normal_disable"
                :key="dict.value"
                :label="dict.value"
            >{{ dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>-->
    <!--
    <el-dialog v-bind="$attrs" v-on="$listeners" @open="onOpen" @close="onClose" title="Dialog Title">
-->
    <!--
    <el-dialog :title="添加客户信息" v-model="open" width="1000px" append-to-body>
-->
    <el-dialog
      v-bind="$attrs"
      v-model="open"
      title="添加客户信息"
      append-to-body
      width="800px"
    >
      <el-form
        ref="companyRef"
        :model="form"
        :rules="rules"
        label-width="100px"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item label="客户全称" prop="fullName">
              <el-input
                v-model="form.fullName"
                placeholder="请输入客户全称"
                :maxlength="50"
                show-word-limit
                clearable
                prefix-icon="mobile"
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="客户编号" prop="companyCode">
              <el-input
                v-model="form.companyCode"
                placeholder="请输入客户编号"
                readonly
                clearable
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户简称" prop="companyName">
              <el-input
                v-model="form.companyName"
                placeholder="请输入客户简称"
                clearable
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款方式" prop="paymentType">
              <el-select
                v-model="form.paymentType"
                placeholder="请选择付款方式"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in pay_type"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款比例" prop="paymentRatio">
              <el-input
                v-model="form.paymentRatio"
                placeholder="请输入付款比例"
                clearable
                :style="{ width: '100%' }"
              >
                <template slot="append">%</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="信用额度" prop="creditLimit">
              <el-input
                v-model="form.creditLimit"
                placeholder="请输入信用额度"
                clearable
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否限额" prop="creditFlag">
              <el-select
                v-model="form.creditFlag"
                placeholder="请选择是否限额"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in sys_yes_no"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="审核状态" prop="approveStatus">
              <!--                  <el-input v-model="form.approveStatus" placeholder="请输入审核状态" readonly clearable
                            :style="{width: '100%'}"></el-input>-->
              <el-select
                disabled
                v-model="form.approveStatus"
                readonly
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in company_audit_status"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户状态" prop="companyStatus">
              <el-select
                disabled
                v-model="form.companyStatus"
                placeholder="请选择客户状态"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in companyStatusOptions"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系人名字" prop="linkName">
              <el-input
                v-model="form.linkName"
                placeholder="请输入联系人名字"
                clearable
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人电话" prop="linkMobile">
              <el-input
                v-model="form.linkMobile"
                placeholder="请输入联系人电话"
                clearable
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="业务员名字" prop="saleUserInfo">
              <el-select
                v-model="selectedSaleUser"
                value-key="userId"
                placeholder=""
                clearable
                filterable
                @change="data.saleUserInfoChange"
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="item in saleUserList"
                  :key="item.userId"
                  :label="item.nickName"
                  :value="item"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="业务员电话" prop="salePhone">
              <el-input
                v-model="form.salePhone"
                placeholder="请输入业务员电话"
                clearable
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="显示品类" prop="genreId">
              <el-checkbox-group v-model="genreIdList">
                <el-checkbox
                  v-for="(item, index) in genreIdOptions"
                  :key="item.value"
                  :label="item.value"
                  :disabled="item.disabled"
                  >{{ item.label }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="结算类型" prop="settlementVersionType">
            <el-select
              v-model="form.settlementVersionType"
              placeholder="请选择结算类型"
              clearable
              :style="{ width: '100%' }"
            >
              <el-option
                v-for="(item, index) in company_settlement_version_type"
                :key="index"
                :label="item.label"
                :value="item.value"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="23">
            <el-form-item label="客户地址" prop="address">
              <el-input
                v-model="form.address"
                placeholder="请输入客户地址"
                clearable
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="14">
            <el-form-item label="所在城市" prop="cityName">
              <el-input
                v-model="form.cityName"
                placeholder="请输入所在城市"
                clearable
                :style="{ width: '100%' }"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" v-if="isDetail" @click="submitForm"
          >确定</el-button
        >
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      v-bind="$attrs"
      v-model="openUpdate"
      title="修改结算类型"
      append-to-body
      width="800px"
    >
      <el-form
        ref="companyUpdateRef"
        :model="form"
        :rules="rules"
        label-width="100px"
      >
        <el-row>
          <el-form-item label="结算类型" prop="settlementVersionType">
            <el-select
              v-model="form.settlementVersionType"
              placeholder="请选择结算类型"
              clearable
              :style="{ width: '100%' }"
            >
              <el-option
                v-for="(item, index) in company_settlement_version_type"
                :key="index"
                :label="item.label"
                :value="item.value"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="submitFormUpdate">确定</el-button>
        <el-button @click="cancelUpdate">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script setup name="Post">
import {
  listCompany,
  getCompany,
  delCompany,
  addCompany,
  updateCompany,
  batchAudit,
  batchAuditSuccess,
  batchAuditFalse,
  disableCompany,
  enableCompany,
  backUpdate,
  listSaleUserList,
} from "@/api/company/company.js";

const { proxy } = getCurrentInstance();
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
const { company_status } = proxy.useDict("company_status");
const { company_audit_status } = proxy.useDict("company_audit_status");
const { pay_type } = proxy.useDict("pay_type");
const { sys_yes_no } = proxy.useDict("sys_yes_no");
const { company_settlement_version_type } = proxy.useDict(
  "company_settlement_version_type"
);
const selectedSaleUser = ref(null); // 响应式变量存储 el-select 选中的对象
const genreIdList = ref([]);
const companyList = ref([]);
const saleUserList = ref([]);
const open = ref(false);
const openUpdate = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const isDetail = ref(true);
const data = reactive({
  formUpdate: {},
  form: {},
  saleUserInfoChange(item) {
    form.value.saleId = item.userId;
    form.value.saleName = item.nickName;
  },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    fullName: undefined,
    companyCode: undefined,
    companyName: undefined,
    companyStatus: "NORMAL",
    genreId: undefined,
    paymentType: undefined,
    paymentRatio: undefined,
    approveStatus: undefined,
    creditLimit: undefined,
    creditFlag: undefined,
    linkName: undefined,
    linkMobile: undefined,
    saleName: undefined,
    cityName: undefined,
    address: undefined,
    salePhone: undefined,
  },
  rules: {
    fullName: [
      { required: true, message: "客户全称不能为空", trigger: "blur" },
    ],
    companyName: [
      { required: true, message: "客户简称不能为空", trigger: "blur" },
    ],
    companyStatus: [
      { required: true, message: "客户状态不能为空", trigger: "blur" },
    ],
    paymentType: [
      { required: true, message: "支付方式不能为空", trigger: "blur" },
    ],
    paymentRatio: [
      { required: true, message: "支付比例不能为空", trigger: "blur" },
    ],
  },
  paymentTypeOptions: [
    {
      label: "实时付款",
      value: 0,
    },
    {
      label: "信用付款",
      value: 1,
    },
  ],
  companyStatusOptions: [
    {
      label: "正常",
      value: "NORMAL",
    },
    {
      label: "停用",
      value: "CANCEL",
    },
  ],
  genreIdOptions: [
    {
      label: "视光版",
      value: "7",
    },
    {
      label: "医疗版",
      value: "8",
    },
  ],
});

const {
  queryParams,
  form,
  rules,
  paymentTypeOptions,
  companyStatusOptions,
  genreIdOptions,
} = toRefs(data);

/** 查询岗位列表 */
function getList() {
  loading.value = true;
  listCompany(queryParams.value).then((response) => {
    companyList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

function handleSaleUserQuery(query) {
  listSaleUserList(query).then((response) => {
    saleUserList.value = response.data;
  });
}

/** 取消按钮 */
function cancel() {
  open.value = false;
  isDetail.value = true;
  genreIdList.value = [];
  reset();
}
/** 取消按钮 */
function cancelUpdate() {
  openUpdate.value = false;
  isDetail.value = true;
  genreIdList.value = [];
  reset();
}
/** 表单重置 */
function reset() {
  form.value = {
    postId: undefined,
    postCode: undefined,
    postName: undefined,
    paymentRatio: undefined,
    postSort: 0,
    companyStatus: null,
    creditFlag: "N",
    remark: undefined,
    settlementVersionType: null,
  };
  selectedSaleUser.value = {
    userId: null,
    userName: null,
  };
  proxy.resetForm("companyRef");
  proxy.resetForm("companyUpdateRef");
  handleQuery();
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.companyId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}
/** 新增按钮操作 */
function handleAdd() {
  handleSaleUserQuery();
  reset();
  open.value = true;
  title.value = "添加岗位";
  genreIdList.value = [];
  isDetail.value = true;
  form.value.companyStatus = "NORMAL";
}

function handleBatchAudit(row) {
  const postIds = row.companyId || ids.value;
  proxy.$modal
    .confirm("是否提交审核所选客户信息？")
    .then(function () {
      return batchAudit(postIds);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("操作成功");
    })
    .catch(() => {});
}

/**
 * 批量审核通过
 */
function handleAuditTrue(row) {
  const postIds = row.companyId || ids.value;
  proxy.$modal
    .confirm("是否审核通过所选客户信息？")
    .then(function () {
      return batchAuditSuccess(postIds);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("操作成功");
    })
    .catch(() => {});
}

/**
 * 批量审核不通过
 */
function handleAuditFalse(row) {
  const postIds = row.companyId || ids.value;
  proxy.$modal
    .confirm("是否审核通过所选客户信息？")
    .then(function () {
      return batchAuditFalse(postIds);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("操作成功");
    })
    .catch(() => {});
}

function handleBatchUpdate(row) {
  handleSaleUserQuery();
  reset();
  isDetail.value = true;
  genreIdList.value = [];
  const companyId = row.companyId;
  getCompany(companyId).then((response) => {
    form.value = response.data;
    open.value = true;
    title.value = "修改";
    form.saleUserInfo = {
      saleId: response.data.saleId,
      userId: response.data.saleId,
      nickName: response.data.saleName,
      saleName: response.data.saleName,
    };
    form.value.saleId = response.data.saleId;
    form.value.nickName = response.data.saleName;
    selectedSaleUser.value = {
      userId: response.data.saleId,
      userName: response.data.saleName,
    };
    genreIdList.value = response.data.genreId.split(",");
    console.log(form.saleUserInfo);
  });
}

function handleUpdate(row) {
  reset();
  genreIdList.value = [];
  const companyId = row.companyId;
  getCompany(companyId).then((response) => {
    form.value = response.data;
    openUpdate.value = true;
    title.value = "修改";
    form.saleUserInfo = {
      saleId: response.data.saleId,
      userId: response.data.saleId,
      nickName: response.data.saleName,
      saleName: response.data.saleName,
    };
    form.value.saleId = response.data.saleId;
    form.value.nickName = response.data.saleName;
    selectedSaleUser.value = {
      userId: response.data.saleId,
      userName: response.data.saleName,
    };
    genreIdList.value = response.data.genreId.split(",");
  });
}

/**
 * 停用
 */
function handleStop() {}
/**
 * 删除
 */
function handleDelete(row) {
  const postIds = row.companyId || ids.value;
  proxy.$modal
    .confirm("是否删除此客户信息")
    .then(function () {
      return delCompany(postIds);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("操作成功");
    })
    .catch(() => {});
}

/** 下架按钮操作 */
function handleBackUpdate(row) {
  reset();
  const companyId = row.companyId || ids.value;
  proxy.$modal
    .confirm("是否下架所选客户")
    .then(function () {
      return backUpdate(companyId);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("操作成功");
    })
    .catch(() => {});
}
/** 提交按钮 */
function submitForm() {
  proxy.$refs["companyRef"].validate((valid) => {
    if (valid) {
      console.log("selectedSaleUser:" + selectedSaleUser.value);
      console.log(form.value.genreId);
      let genreIds = "";
      for (let i in form.value.genreId) {
        genreIds = genreIds + form.value.genreId[i] + ",";
      }

      form.value.genreId = genreIdList.value.join(",");
      if (form.value.companyId != undefined) {
        updateCompany(form.value).then((response) => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addCompany(form.value).then((response) => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 提交按钮 */
function submitFormUpdate() {
  proxy.$refs["companyUpdateRef"].validate((valid) => {
    if (valid) {
      console.log(form.value.genreId);
      let genreIds = "";
      for (let i in form.value.genreId) {
        genreIds = genreIds + form.value.genreId[i] + ",";
      }
      form.value.genreId = genreIdList.value.join(",");
      updateCompany(form.value).then((response) => {
        proxy.$modal.msgSuccess("修改成功");
        openUpdate.value = false;
        getList();
      });
    }
  });
}

function handleView(row) {
  open.value = true;
  form.value = { ...row };
      selectedSaleUser.value = {
      userId: row.saleId,
      userName: row.saleName,
    };
  isDetail.value = false;
  genreIdList.value = row.genreId.split(",");
  console.log(genreIdList.value);
  handleSaleUserQuery();
}

/** 停用按钮操作 */
function handleDisable(row) {
  const postIds = row.companyId || ids.value;
  proxy.$modal
    .confirm("是否停用此客户信息")
    .then(function () {
      return disableCompany(postIds);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("操作成功");
    })
    .catch(() => {});
}

/** 启用按钮操作 */
function handleEnable(row) {
  const postIds = row.companyId || ids.value;
  proxy.$modal
    .confirm("是否启用此客户信息")
    .then(function () {
      return enableCompany(postIds);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("操作成功");
    })
    .catch(() => {});
}

/** 导出按钮操作 */

getList();
</script>
